﻿Imports Windows.Devices.Enumeration.Pnp

Namespace Utility
    Public Module DeviceInfo
        ''' <summary>
        ''' 获取设备的制造商，型号，唯一标志以及软件版本号.
        ''' </summary>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Async Function GetDeviceInfo() As Task(Of String)
            Dim result = String.Empty
            Dim deviceModel = String.Empty
            Dim deviceManufacturer = String.Empty
            Dim uniqueId = String.Empty

            Dim properties = {"System.Devices.ModelName", "System.Devices.Manufacturer"}
            Dim aqs = "System.Devices.LocalMachine:=System.StructuredQueryType.Boolean#True"

            Dim containers = Await PnpObject.FindAllAsync(PnpObjectType.DeviceContainer, properties, aqs)
            If containers IsNot Nothing AndAlso containers.Count > 0 Then
                Dim container = containers(0)
                Try
                    deviceModel = container.Properties(properties(0))
                    deviceManufacturer = container.Properties(properties(0))
                Catch
                    deviceModel = "Model"
                    deviceManufacturer = "Manufacturer"
                End Try
            End If

            Dim version = Package.Current.Id.Version

            result = String.Format("{0}_{1}__V{2}.{3}.{4}", deviceManufacturer, deviceModel, version.Major, version.Minor, version.Build)

            Return result
        End Function
    End Module
End Namespace